package com.hunlian.makelove.net.api;

import android.content.Context;

import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.hunlian.makelove.net.ServiceInterfaceDef;
import com.hunlian.makelove.net.InterfaceServiceVisit;
import com.hunlian.makelove.net.ResponseCallbackListener;
import com.hunlian.makelove.net.StringResponseCallbackListener;
import com.hunlian.makelove.bean.Person;

import java.lang.reflect.Type;
import java.util.ArrayList;


/**
 * 邀请我
 * @author zealjiang
 * @time 2015年11月23日下午2:08:24
 */
public class ReceveInvitingServiceVisit extends InterfaceServiceVisit {
	// 邀请我接口Id


	public ReceveInvitingServiceVisit(Context context) {
		super(context);

		setFunctionId(ServiceInterfaceDef.FUNC_ID_RECEIVE_INVITING);
	}

	// 填充参数
	public void setParamters(String userId,String pageSize,String currentPage) {
		paramterData.put("userId", userId);
		paramterData.put("pageSize", pageSize);
		paramterData.put("page", currentPage);
	}

	public void getResult(final ResponseCallbackListener<ArrayList<Person>,Object> listener) {
		doPost(getParamter(), new StringResponseCallbackListener() {
			@Override
			public void onSuccess(String data) {
				//Printout.println("邀请我:"+data);
			
				Type listType = new TypeToken<ArrayList<Person>>(){}.getType();
				Gson gson = new Gson();
				ArrayList<Person> persons = gson.fromJson(data, listType);
/*		        for (Iterator iterator = persons.iterator(); iterator.hasNext();) {
		        	Person city = (Person) iterator.next();
		        }*/
		        
				if(listener != null){
					listener.onSuccess(persons);
				}
			}

			@Override
			public void onFailure(String errCode, String errMessage,String str) {
				if (listener != null) {
					listener.onFailure(errCode, errMessage,str);
				}
			}
		});
	}


}
